package d8_test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 2024/6/28 Cjj 8：58
 */
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {

        //目标：有100份礼品,小红,小明俩人同时发送,当剩下的礼品小于10份的时候则不再送出
        //利用多线程模拟过程并将线程的名称打印出来。并最后在控制台分别打印小红，小明各自送出多少份礼物
        //1.拿100份礼品到程序中
        List<String> gift = new ArrayList<>();
        String[] names = {"口红", "包包", "鲜花", "剃须刀", "皮带", "手表"};
        Random r = new Random();
        for (int i = 0; i < 100; i++) {
            gift.add(names[r.nextInt(names.length)] + (i + 1));
        }
        System.out.println(gift);

        //2.定义线程类,创建线程对象,去集合中拿礼物给别人
        SendThread xm = new SendThread(gift, "小明");
        xm.start();
        SendThread xh = new SendThread(gift, "小红");
        xh.start();

        xm.join();
        xh.join();

        System.out.println(xm.getCount());
        System.out.println(xh.getCount());
    }
}
